<% layout('layout') -%>

<div id='content'>
  <div class='panel'>
    <div class='header'>
      <ol class='breadcrumb'>
        <li><a href='/'>主页</a><span class='divider'>/</span></li>
        <% if(typeof action !== 'undefined' && action == 'edit'){ %>
        <li class='active'>编辑话题</li>
        <% } else { %>
        <li class='active'>发布话题</li>
        <% } %>
      </ol>
    </div>
    <div class='inner post'>
      <% if(typeof edit_error !== 'undefined' && edit_error){ %>
      <div class="alert alert-error">
        <a class="close" data-dismiss="alert" href="#">&times;</a>
        <strong><%= edit_error %></strong>
      </div>
      <% } %>
      <% if(typeof error !== 'undefined' && error){ %>
      <div class="alert alert-error">
        <strong><%= error %></strong>
      </div>
      <% } else { %>
      <% if (typeof action !== 'undefined' && action === 'edit') { %>
      <form id='create_topic_form' action='/topic/<%= topic_id %>/edit' method='post'>
        <% } else { %>
        <form id='create_topic_form' action='/topic/create' method='post'>
          <% } %>
          <fieldset>
            <span class="tab-selector">选择版块：</span>
            <select name="tab" id="tab-value">
              <option value="">请选择</option>
              <%
              var tabValue = '';
              if (typeof tab !== 'undefined') {
                tabValue = tab;
              }
              tabs.forEach(function (pair) {
                var value = pair[0];
                var text = pair[1];
                %>
                <option value="<%=value%>" <%= tabValue === value ? 'selected': '' %>><%=text%></option>

              <%});%>
            </select>
            <span id="topic_create_warn"></span>
            <textarea autofocus class='span9' id='title' name='title' rows='1'
                      placeholder="标题字数 10 字以上"
                    ><%= typeof title !== 'undefined' && title || '' %></textarea>

            <div class='markdown_editor in_editor'>
              <div class='markdown_in_editor'>
                <textarea class='editor' name='content' rows='20'
                          placeholder='文章支持 Markdown 语法, 请注意标记代码'
                        ><%= typeof content !== 'undefined' && content || '' %></textarea>

                <div class='editor_buttons'>
                  <input type="submit" class='span-primary submit_btn' data-loading-text="提交中"
                         value="提交">
                </div>
              </div>

            </div>

            <input type='hidden' id='topic_tags' name='topic_tags' value=''>
            <input type='hidden' name='_csrf' value='<%= csrf %>'>
          </fieldset>
        </form>
    </div>
    <% } %>
  </div>
</div>